// pages/cardList/cardList.js
var util = require('../../utils/util')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    animation: '',
    name: '',
    list: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let data = wx.getStorageSync('wys')
    data.forEach((item, index, arr) => {
      let title = item.equipment && (item.warranty_brand_code == 'S' || item.warranty_brand_code == 'T') ? item.equipment : item.warranty_category + '  ' + item.warranty_model;
      if (title.length > 14) {
        item.animation = 'kf-marque-animation 4s linear infinite'
      } else {
        item.animation = ''
      }
      this.setData({
        list: arr
      })
    })
    let name = this.data.name.length;
    if (name > 21) {
      this.setData({
        animation: 'kf-marque-animation 4s linear infinite'
      })
    } else {
      this.setData({
        animation: ''
      })
    }
  },
  lookup(e) {
    var ind = e.currentTarget.dataset.index;
    this.distinguish(this.data.list[ind].warranty_code)
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },
  distinguish: function (result) {
    wx.showLoading({
      title: '跳转中',
    })
    util.request('/model/detail', {
      brand_code: result.substring(0, 1),
      category_code: result.substring(1, 3),
      model_code: result.substring(3, 5)
    }, "GET").then(res => {
      console.log(res)
      let list = res.data;
      wx.hideLoading({
        success: (res) => {},
      })
      list[0].res_code = result;
      wx.navigateTo({
        url: '../' + list[0].page + '/' + list[0].page + '?data=' + JSON.stringify(list[0]),
      })
    })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})